﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace LicMagnaCmsData
{
    public class MnCmsDataGet
    {
        /// <summary>
        /// 麦格纳CMS数据获取 Add By Quinn.Ling 201708
        /// </summary>
        /// 
        #region WebService调用
        public static MagnaDataSet cmsdata = new MagnaDataSet();
        #endregion

        public static string GetCmsData(List<string> DataList)
        {
      
            #region 通用变量定义
            string result = string.Empty;
            List<string> sqllists = new List<string>();
            string strSql = string.Empty;
            #endregion

            try
            {
                #region 数据传递发送
                if (DataList.Count > 0)
                {
                    for (int i = 0; i < DataList.Count; i++)
                    {
                        string TableName = DataList[i];
                        try
                        {
                            strSql = "SELECT * FROM "+ TableName;
                            DataTable dt = App.GetDataTable(App.DBconWMS, strSql, "CMSDATA");
                            if (dt.Rows.Count > 0)
                            {
                                result = App.DataTable2Xml(dt);

                                //测试调用本地方法
                                //MnCmsDataSet.SetCmsData(result, TableName);

                                cmsdata.CmsDataSet(result, TableName);  //调用WebService传输数据
                                App.Log("GetCmsData-1.0", "已成功同步数据表：" + TableName);
                            }
                            else
                            {
                                App.Log("GetCmsData-1.0", "数据表：" + TableName +"无可同步数据");
                            }

                        }
                        catch (Exception ex)
                        {
                            App.Log("GetCmsData-1.0", ex.Message.ToString());
                        }
                    }
                }
                #endregion

            }
            catch (Exception ex)
            {
                App.Log("GetCmsData-1.1", ex.Message.ToString());
            }
            return result;
        }
    }
}
